package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.ApartmentFeeValue;
import com.atguigu.lease.web.app.service.ApartmentFeeValueService;
import com.atguigu.lease.web.app.service.FeeKeyService;
import com.atguigu.lease.web.app.vo.fee.FeeValueVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.atguigu.lease.model.entity.FeeValue;
import com.atguigu.lease.web.app.service.FeeValueService;
import com.atguigu.lease.web.app.mapper.FeeValueMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
* @author liubo
* @description 针对表【fee_value(杂项费用值表)】的数据库操作Service实现
* @createDate 2023-07-26 11:12:39
*/
@Service
public class FeeValueServiceImpl extends ServiceImpl<FeeValueMapper, FeeValue>
    implements FeeValueService{
    @Autowired
    private ApartmentFeeValueService apartmentFeeValueService;
    @Autowired
    private FeeKeyService feeKeyService;

    @Override
    public List<FeeValueVo> getRoomFeeValueVoListById(Long id) {
        List<FeeValueVo> feesValueVoList = new ArrayList<>();
        List<ApartmentFeeValue> apartmentFeeValueList = apartmentFeeValueService.list(new LambdaQueryWrapper<ApartmentFeeValue>().eq(ApartmentFeeValue::getApartmentId, id));
        List<FeeValue> feeValueList = new ArrayList<>();
        if (apartmentFeeValueList != null && !apartmentFeeValueList.isEmpty()) {
            for (ApartmentFeeValue apartmentFeeValue : apartmentFeeValueList) {
                feeValueList = this.list(new LambdaQueryWrapper<FeeValue>().eq(FeeValue::getId, apartmentFeeValue.getFeeValueId()));
            }
            for (FeeValue feeValue : feeValueList) {
                FeeValueVo feeValueVo = new FeeValueVo();
                feeValueVo.setId(feeValue.getId());
                feeValueVo.setName(feeValue.getName());
                feeValueVo.setUnit(feeValue.getUnit());
                feeValueVo.setFeeKeyName(feeKeyService.getById(feeValue.getFeeKeyId()).getName());
                feesValueVoList.add(feeValueVo);
            }
        }

        return feesValueVoList;
    }
}




